# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=netexec
_pyver=3.13
pkgver=v1.4.0.r1338.g69c87d2
pkgrel=1
groups=('blackarch' 'blackarch-scanner' 'blackarch-exploitation'
        'blackarch-networking' 'blackarch-windows')
pkgdesc='A Windows / Active Directory environments pentest tool.'
arch=('any')
url='https://netexec.wiki/'
license=('BSD')
# need rust for aardwolf
makedepends=('git' 'rust' 'python-virtualenv')
source=("$pkgname::git+https://github.com/Pennyw0rth/NetExec.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd $pkgname

  virtualenv venv
  source venv/bin/activate
  pip install pyinstaller . # it does not work with system pyinstaller

  pyinstaller netexec.spec

  deactivate
}

package() {
  cd $pkgname

  install -Dm 755 ./dist/nxc "$pkgdir/usr/bin/$pkgname"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  ln -s "/usr/bin/$pkgname" "$pkgdir/usr/bin/nxc"

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

